package com.share.sharedevice.controller;

import com.share.common.core.domain.R;
import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.page.TableDataInfo;
import com.share.sharedevice.dto.StationDto;
import com.share.sharedevice.entity.Station;
import com.share.sharedevice.service.IStationService;
import com.share.sharedevice.vo.StationVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "站点接口管理")
@RestController
@RequestMapping("/station")
public class StationController extends BaseController {

    @Autowired
    private IStationService stationService;

    @GetMapping("/list")
    public TableDataInfo list(StationVo stationVo){
        startPage();
        List<Station> stationList = stationService.selectStationList(stationVo);
        return getDataTable(stationList);
    }

    /**
     * 获取站点详细信息
     */
    @GetMapping("/{id}")
    public R<StationVo> getInfo(@PathVariable("id") Long id) {

        StationVo station = stationService.getByStationId(id);

        return R.ok(station);
    }

    /**
     * 删除站点
     */
    @DeleteMapping("/{ids}")
    public R<StationVo> delete(@PathVariable("ids") List<Long> ids){
        stationService.delete(ids);
        return R.ok();
    }

    /**
     * 新增站点
     */
    @PostMapping
    public R<StationDto> add(@RequestBody StationDto stationDto){
        stationService.add(stationDto);
        return R.ok();
    }


    /**
     * 修改站点
     */
    @PutMapping
    public R<StationDto> update(@RequestBody StationDto stationDto){
        stationService.updateByStationId(stationDto);
        return R.ok();
    }
}
